<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script type="text/javascript"
	src=" https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script type="text/javascript"
	src=" https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js"></script>
<html>

<head>
<title>#{get 'title' /}</title>

<script type="text/javascript">
  function prepareCreatePostTopic(){
        if(document.getElementById("type").value=="entity"){
		  createPostTopicEntity();
	  }else{
		  createPostTopicOrg();
	  }
  }
  </script>

<script type="text/javascript">
  function prepareDraftTopic(){
	  if(document.getElementById("type").value=="entity"){
		 draftTopicEntity();
	  }else{
		  draftTopicOrg();
	  }
  }
 
  
  </script>
<script type="text/javascript">
      function checkTopicValidationCreate(){
          var isAlphaNeumeric =/^[0-9a-zA-Zs ]+$/;
          var title=document.getElementById("topic_title").value;
          var descr=document.getElementById("topic_descr").value;

       if(title==null||title==""){
             document.getElementById("topictitleexp").innerHTML="Title required"
         }else{
             if(!(isAlphaNeumeric.test(title))){
                  document.getElementById("topictitleexp").innerHTML="Title can't contain foreign character";
             }else{
                 if(title.indexOf(" ")==0){
                      document.getElementById("topictitleexp").innerHTML="Title can't start with space";
                 }else{
                 if(title.length>25){
                      document.getElementById("topictitleexp").innerHTML="Title can't be more than 25 letters";
                 }else{
              document.getElementById("topictitleexp").innerHTML="" ;
                 }
         }
         }
         }
           if(descr==null||descr==""){
             document.getElementById("topicdescrexp").innerHTML="Description required"

         }else{
              if(!(isAlphaNeumeric.test(descr))){
                  document.getElementById("topicdescrexp").innerHTML="Description can't contain Foreign characters";
             }else{
                 if(descr.indexOf(" ")==0){
                     document.getElementById("topicdescrexp").innerHTML="Description can't start with space" ;
                 }else{
              document.getElementById("topicdescrexp").innerHTML="" ;
         }
         }
         }

if(document.getElementById("topicdescrexp").innerHTML=="" && document.getElementById("topictitleexp").innerHTML==""){
return true
}
else{
return false;
}

  }





    function checkTopicValidationDraft(){
       var title=document.getElementById("drafttopic_title").value;
var descr=document.getElementById("drafttopic_descr").value;
var isAlphaNeumeric =/^[0-9a-zA-Zs ]+$/;
         if(title==null||title==""){
             document.getElementById("drafttopictitleexp").innerHTML="Title required"
         }else{
             if(!(isAlphaNeumeric.test(title))){
                  document.getElementById("drafttopictitleexp").innerHTML="Title can't contain foreign characters";
             }else{
                 if(title.indexOf(" ")==0){
                      document.getElementById("drafttopictitleexp").innerHTML="Title can't start with space";
                 }else{
                 if(title.length>25){
                      document.getElementById("drafttopictitleexp").innerHTML="Title can't be more than 25 letters";
                 }else{
              document.getElementById("drafttopictitleexp").innerHTML="" ;
                 }
         }
         }
         }
         if(descr==null||descr==""){
             document.getElementById("drafttopicdescrexp").innerHTML="Description required"

         }else{
              if(!(isAlphaNeumeric.test(descr))){
                  document.getElementById("drafttopicdescrexp").innerHTML="Description can't contain Foreign characters";
             }else{
                 if(descr.indexOf(" ")==0){
                     document.getElementById("drafttopicdescrexp").innerHTML="Description can't start with space" ;
                 }else{
              document.getElementById("drafttopicdescrexp").innerHTML="" ;
         }
         }
         }

if(document.getElementById("drafttopicdescrexp").innerHTML=="" && document.getElementById("drafttopictitleexp").innerHTML==""){
return true
}
else{
return false;
}

  }






        </script>

<script type="text/javascript">
          function createPostTopicEntity(){
              if(checkTopicValidationCreate()){

                  var title=document.getElementById("topic_title").value;

                  var descr=document.getElementById("topic_descr").value;
                  var visibility=document.getElementById("topicVisibility").value;

                 $.post("@{TopicIdeaController.postTopicEntity()}",
                 {'title':title,'description':descr,'visibility':visibility ,'entityId':'${entityId}' },
  function(data){
  $("<li><a href=@{TopicIdeaController.checkAuthorizationToViewTopic()}?topicId="+data.topicId+">"+data.topicTitle+"</a></li>")
 .appendTo(document.getElementById("Topics"))
 document.getElementById("topic_title").value="";
 document.getElementById("topic_descr").value="";
 document.getElementById("topictitleexp").innerHTML="Topic Required";
 document.getElementById("topicdescrexp").innerHTML="Description Required";
  $('#createTopics').fadeOut(1000);

  },"json")
              }else{
                  alert("Wrong input! only letters and numbers are allowed")
              }
          }
      </script>


<script type="text/javascript">
          function draftTopicEntity(){
              if(checkTopicValidationCreate()){

                  var title=document.getElementById("topic_title").value;

                  var descr=document.getElementById("topic_descr").value;
                  var visibility=document.getElementById("topicVisibility").value;

                 $.post("@{TopicIdeaController.draftTopicEntity()}",
                 {'title':title,'description':descr,'visibility':visibility ,'entityId':'${entityId}'
                     },
  function(data){

    $("<li><a id="+"draftTopicLink"+data.topicId+" href='javascript:displayCreateDiv2("+data.topicId+",\""+data.topicTitle+"\",\""+data.topicDescription+"\")'>"+data.topicTitle+"</a></li>")
   .appendTo(document.getElementById("draftedTopicList"));

   document.getElementById("topic_title").value="";
 document.getElementById("topic_descr").value="";
 document.getElementById("topictitleexp").innerHTML="Topic Required";
 document.getElementById("topicdescrexp").innerHTML="Description Required";
  $('#createTopics').fadeOut(1000);
  },"json")
              }else{
                  alert("Wrong input! only letters and numbers are allowed")
              }
          }
      </script>

<script type="text/javascript">
          function createPostTopicOrg(){
              if(checkTopicValidationCreate()){
                  
                  var title=document.getElementById("topic_title").value;

                  var descr=document.getElementById("topic_descr").value;
                  var visibility=document.getElementById("topicVisibility").value;

                 $.post("@{TopicIdeaController.postTopicOrganization()}",
                 {'title':title,'description':descr,'visibility':visibility ,'orgId':'${orgId}'
                      },
  function(data){

  $("<li><a href=@{TopicIdeaController.checkAuthorizationToViewTopic()}?topicId="+data.topicId+">"+data.topicTitle+"</a></li>")
 .appendTo(document.getElementById("Topics"))
 document.getElementById("topic_title").value="";
 document.getElementById("topic_descr").value="";
 document.getElementById("topictitleexp").innerHTML="Topic Required";
 document.getElementById("topicdescrexp").innerHTML="Deascription Required";
  $('#createTopics').fadeOut(1000);
  },"json")
              }else{
                 alert("Wrong input! only letters and numbers are allowed")
              }
          }
      </script>


<script type="text/javascript">
          function draftTopicOrg(){
              if(checkTopicValidationCreate()){

                  var title=document.getElementById("topic_title").value;

                  var descr=document.getElementById("topic_descr").value;
                  var visibility=document.getElementById("topicVisibility").value;

                 $.post("@{TopicIdeaController.draftTopicOrganization()}",
                 {'title':title,'description':descr,'visibility':visibility ,'orgId':'${orgId}'},
  function(data){

   //alert(data.topicId);
   //alert(data.topicTitle);
   //alert(data.topicDescription);
   $("<li><a id="+"draftTopicLink"+data.topicId+" href='javascript:displayCreateDiv2("+data.topicId+",\""+data.topicTitle+"\",\""+data.topicDescription+"\")'>"+data.topicTitle+"</a></li>")
   .appendTo(document.getElementById("draftedTopicList"));

   document.getElementById("topic_title").value="";
 document.getElementById("topic_descr").value="";
 document.getElementById("topictitleexp").innerHTML="Topic Required";
 document.getElementById("topicdescrexp").innerHTML="Description Required";
  $('#createTopics').fadeOut(1000);
  },"json")
              }else{
                 alert("Wrong input! only letters and numbers are allowed")
              }
          }
        


 function discard3(){
 document.getElementById("topic_title").value=" ";
 document.getElementById("topic_descr").value=" ";
 document.getElementById("topicdescrexp").innerHTML="Title Required";
 document.getElementById("topictitleexp").innerHTML="Description Required";
     $('#createTopics').fadeOut(1000);
 }

 function discard2(){
  var topicId=document.getElementById("draftTopicId").value;
  $('#draftTopicLink'+topicId).remove();
 document.getElementById("drafttopic_title").value="";
 document.getElementById("drafttopic_descr").value="";
 document.getElementById("drafttopicdescrexp").innerHTML="";
 document.getElementById("drafttopictitleexp").innerHTML="";
     $('#draftedTopicsDivDiv').fadeOut(1000);
 }


 function postDraftTopic(){
     if(checkTopicValidationDraft()){
        var topicId=document.getElementById("draftTopicId").value;
       var title=document.getElementById("drafttopic_title").value;
         var descr=document.getElementById("drafttopic_descr").value;
         var visibility=document.getElementById("drafttopicVisibility").value;

      $.post("@{TopicIdeaController.postDraftTopic()}",
                 {'topicId':topicId,'title':title,'description':descr,'visibility':visibility },
  function(data){
 $('#draftTopicLink'+topicId).remove();
 $("<li><a href=@{TopicIdeaController.checkAuthorizationToViewTopic()}?topicId="+data.topicId+">"+data.topicTitle+"</a></li>")
 .appendTo(document.getElementById("Topics"));
 document.getElementById("drafttopic_title").value="";
 document.getElementById("drafttopic_descr").value="";
 document.getElementById("drafttopicdescrexp").innerHTML="";
document.getElementById("drafttopictitleexp").innerHTML="";
  $('#draftedTopicsDivDiv').fadeOut(1000);
 }

 ,"json")
 }
 }

 function draftDraftTopic(){
 if(checkTopicValidationDraft()){
          var topicId=document.getElementById("draftTopicId").value;
       var title=document.getElementById("drafttopic_title").value;
                  var descr=document.getElementById("drafttopic_descr").value;
                  var visibility=document.getElementById("drafttopicVisibility").value;

      $.post("@{TopicIdeaController.draftDraftTopic()}",
                 {'topicId':topicId,'title':title,'description':descr,'visibility':visibility },
  function(data){
  $('#draftTopicLink'+topicId).remove();
$("<li><a id="+"draftTopicLink"+data.topicId+" href='javascript:displayCreateDiv2("+data.topicId+",\""+data.topicTitle+"\",\""+data.topicDescription+"\")'>"+data.topicTitle+"</a></li>")
   .appendTo(document.getElementById("draftedTopicList"));
 document.getElementById("drafttopic_title").value=" ";
 document.getElementById("drafttopic_descr").value=" ";
 document.getElementById("drafttopicdescrexp").innerHTML="";
document.getElementById("drafttopictitleexp").innerHTML="";
  $('#draftedTopicsDivDiv').fadeOut(1000);
 }
 ,"json")
 }
 }

      </script>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>

	#{doLayout /}
	<div id="createTopics" style="display: none" class="white_content">

		<input type="hidden" id="type" value=${type} /> Topic_Title: <input
			type="text" id="topic_title" name="title" /> <label
			id="topictitleexp"> Title Required</label> <br> <br>
		Topic_Description: <br>
		<textarea rows="3" cols="30 max" id="topic_descr" name="description"></textarea>
		<label id="topicdescrexp"> Description Required</label> <br /> <br>
		<br> please select the topic visibility: <select
			id="topicVisibility" name="visibility">
			<option value="public">public</option>
			<option value="Hidden">Hidden</option>
		</select>
		<!--Tag_Topic: <input type="text" name="tag" /><br />
-->
		<br> <input type="button" id="submit1" value="Post"
			onclick="javascript:prepareCreatePostTopic()"> <input
			type="button" id="submit" value="Draft"
			onclick="javascript:prepareDraftTopic()"> <input
			type="button" value="discard" onclick="javascript:discard3()" />
	</div>

	<div id="draftedTopicsDivDiv" style="display: none"
		class="white_content">

		<input type="hidden" id="type" value=${type} /> <input type="hidden"
			id="draftTopicId" value=""> Topic_Title: <input type="text"
			id="drafttopic_title" name="title" /> <label id="drafttopictitleexp"></label><br />
		Topic_Description:
		<textarea rows="3" cols="30 max" id="drafttopic_descr"
			name="description"></textarea>
		<label id="drafttopicdescrexp"></label> <br /> <br> <br>
		please select the topic visibility: <select id="drafttopicVisibility"
			name="visibility">
			<option value="public">public</option>
			<option value="Hidden">Hidden</option>
		</select>
		<!--Tag_Topic: <input type="text" name="tag" /><br />
-->
		<br> <input type="button" id="draftsubmit" value="Post"
			onclick="javascript: postDraftTopic()"> <input type="button"
			id="draftsubmit" value="Draft" onclick="javascript:draftDraftTopic()">
		<input type="button" id="discardsubmit" value="discard"
			onclick="javascript:discard2()" />
	</div>

</body>
</html>
